package com.dyz.LeetCodeforSwordFingerOffer;

import java.util.Stack;
/**
 * @ClassNamereversePrint06
 * @Description
 * @Author: daiyizheng
 * @Date2021/6/13 4:38 下午
 * @Version V1.0
 **/
public class reversePrint06 {
    public int[] reversePrint(ListNode head) {
        if(head==null){
            return new int[]{};
        }
        //
        int size=0;
        Stack<ListNode> ans = new Stack<>();

        //计算链表的大小，并且保存到栈中
        while(head!=null){
            size++;
            ans.push(head);
            head = head.next;
        }

        int[] arr = new int[size];
        int index = 0;
        while(ans!=null){
            ListNode node = ans.pop();
            arr[index++] = node.val;
        }
        return arr;

    }
}
